IF EXISTS(SELECT name FROM sysobjects
      WHERE name = 'pInProdHistory_Get' AND type = 'P')
   DROP PROCEDURE pInProdHistory_Get
GO

CREATE PROCEDURE dbo.pInProdHistory_Get
	@productId INT
AS


/*______________________ CONSTANT DECLARATIONS _________________________*/

  

/*______________________ VARIABLE DECLARATIONS _________________________*/

  
/*_______________________________ INIT _________________________________*/


/*________________________ VALIDATE PARAMETERS _________________________*/
	
/*_______________________________ MAIN _________________________________*/
	
	
	SELECT pd.Amount, 
		pp.Date, 
		pd.InputPrice, 
		pd.RemainAmount,
		TotalInputPrice = pd.InputPrice * pd.Amount,
		RowNumber = ROW_NUMBER()OVER(ORDER BY pp.Date DESC)
	FROM InOutProdDetail pd 
	
	INNER JOIN InOutProdPaper pp
	ON pd.InOutProdPaperId = pp.Id
	
	WHERE ProductId = @productId AND pp.Type = 0
	ORDER BY pp.Date DESC

/*___________________________ ERROR HANDLER ____________________________*/



